let mongoose = require('./db')

let LoginSchema = new mongoose.Schema({
    username: String,
    password: String
})

// 会话模型
let ConversationSchema = new mongoose.Schema({
    conversationId: { type: String, required: true, unique: true },
    userId: String,                    // 访客ID
    serviceId: String,                 // 客服ID
    customerName: String,              // 客户名称
    customerInfo: {                    // 客户基本信息
        phone: String,                 // 电话
        email: String,                 // 邮箱
        company: String,               // 公司
        source: String,                // 来源
    },
    // status: {
    //     type: String,
    //     enum: ['ai', 'waiting', 'in_service', 'ended'],  // AI对话、人工服务中
    //     default: 'ai'
    // },
    startTime: { type: Date, default: Date.now },
    endTime: Date,
    messages: [{
        content: String,               // 消息内容
        type: {                        // 消息类型
            type: String,
            enum: ['user', 'service']   // 信息类型 user方左侧，service方右侧常规对话布局
        },
        timestamp: { type: Date, default: Date.now }
    }],
    visitorInfo: {                     // 访客信息
        ip: String,
        browser: String,
        firstVisit: Boolean
    }
})

let LoginModel = mongoose.model('login', LoginSchema, 'login')
let ConversationModel = mongoose.model('conversation', ConversationSchema, 'conversations')

module.exports = { 
    LoginModel,
    ConversationModel
}